package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.AddressMapper;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 李希
 * @date 2019/11/18
 * Time: 21:22
 */
@Service(interfaceClass = AddressService.class)
@Transactional
public class AddressServiceImpl implements AddressService {
    @Autowired
private AddressMapper addressMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        System.out.println(queryString);
        PageHelper.startPage(currentPage, pageSize);
        Page<Address> addressList=addressMapper.queryByCondition(queryString);
        return  new PageResult(addressList.getTotal(), addressList);
    }

    @Override
    public void add(Address address) {
        addressMapper.add(address);
    }

    @Override
    public void delete(Integer id) {
        addressMapper.delete(id);
    }

    @Override
    public List<String> findAddress() {
        return addressMapper.findAddress();
    }

    @Override
    public List<Address> findAll() {
        return addressMapper.findAll();
    }
}